package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.result.Result;
import com.example.common.result.YiFeiException;
import com.example.entity.yifei.Coptn;
import com.example.entity.yifei.Copto;
import com.example.mapper.CoptnMapper;
import com.example.service.CoptoService;
import com.example.mapper.CoptoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 14501
* @description 针对表【COPTO】的数据库操作Service实现
* @createDate 2024-08-08 16:06:08
*/
@Service
public class CoptoServiceImpl extends ServiceImpl<CoptoMapper, Copto>
    implements CoptoService{

    @Resource
    private CoptnMapper coptnMapper;

    @Resource
    private CoptoMapper coptoMapper;

    @Override
    public Result<List<Copto>> queryList(String to001, String to002) {
        try {
            List<Copto> coptoList = coptoMapper.selectList(new LambdaQueryWrapper<Copto>().eq(Copto::getTO001, to001).eq(Copto::getTO002, to002));
            if (!coptoList.isEmpty()){
                coptoList.forEach(arr -> {
                    arr.setCkName(coptoMapper.queryCkName(arr.getTO011()));
                });
            }
            return Result.success(coptoList);
        }catch (Exception e){
            throw new YiFeiException(500,"查询出货通知单详情发生异常"+e.getMessage());
        }

    }

    @Override
    public Result<Coptn> queryOne(String tn001, String tn002) {
      try{
          Coptn coptn = this.coptnMapper.queryOne(tn001, tn002);
          if (coptn!=null){
              List<Copto> coptoList = coptoMapper.selectList(new LambdaQueryWrapper<Copto>().eq(Copto::getTO001, coptn.getTN001()).eq(Copto::getTO002, coptn.getTN002()));
              if (!coptoList.isEmpty()){
                  coptoList.forEach(arr -> {
                      arr.setCkName(coptoMapper.queryCkName(arr.getTO011()));
                  });
              }
              coptn.setCoptoList(coptoList);
          }
          return Result.success(coptn);
      }catch (Exception e){
          throw new YiFeiException(500, "查询单头单身详情发生异常"+e.getMessage());
      }
    }
}




